<?php
/**
 * Created by PhpStorm.
 * User: t
 * Date: 2024/3/21
 * Time: 14:07
 * @copyright: ©2024 永州 微聚商网络科技有限公司
 * @link: https://www.wEijuyunke.com
 */
namespace app\admin\controller;

use app\merchant\model\PayAmount;
use app\merchant\model\PayType;
use app\Request;


class Pay
{
    public  function  payConfig(){
       $payTypeModel =  new PayType();
       $parentList = $payTypeModel->where(['pid' => 0])->select()->toArray();
       $sonList = $payTypeModel->where('pid','>',0)->select()->toArray();
       $parentListById  =  array_column($parentList,null,'id');
       foreach ($sonList as $value){
           if (array_key_exists($value['pid'],$parentListById)  ){
               $parentListById[$value['pid']]['son'][] = $value;
           }
       }
       return adminSuccess('支付配置列表',array_values($parentListById));
    }

    public function upPay(Request $request){
        $param = $request->param();
        $payTypeModel =  new PayType();
        if ($param['status'] == 0){
          $payTypeModel->where('id', $param['id'])
                ->whereOr('pid', $param['id'])->update(['status'=>$param['status']]);
        }else{
            $payTypeModel->where('id', $param['id'])
             ->update(['status'=>$param['status']]);
        }
        return adminSuccess('修改成功');
    }

    public function payAmount(){
        $payAmount  = new PayAmount();
        $list = $payAmount->select();
        $count = $payAmount->count();
        return adminSuccess('支付金额',['list'=> $list,'count' =>$count ]);
    }
    public  function addPayAmount(Request $request){
        $param  = $request->param();
        $payAmountModel = new PayAmount();
        $payAmountModel->insert(['amount' => $param['amount'],'give_amount'=> $param['give_amount'],'create_time'=> time()]);
        return adminSuccess('添加成功');
    }

    public  function editPayAmount(Request $request){
        $param  = $request->param();
        $payAmountModel = new PayAmount();
        $payAmountModel->where(['id' => $param['id']])
            ->update(['amount' => $param['amount'],
                'give_amount'=> $param['give_amount'],
                'create_time'=> time()]);
        return adminSuccess('修改成功');
    }

    public function delPayAmount(Request $request){
        $param  = $request->param();
        $payAmountModel = new PayAmount();
        $payAmountModel->where(['id' => $param['id']])->delete();
        return adminSuccess('删除成功');
    }

    public  function setStatus(Request $request){
        $param  = $request->param();
        $payAmountModel = new PayAmount();
        $payAmountModel->where(['id' => $param['id']])->update(['status' => $param['status']]);
        return adminSuccess('操作成功');
    }



}